﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace YXShop.Web.admin.include
{
    public partial class storelist_ajax : System.Web.UI.Page
    {
        YXShop.BLL.Store.Store bll = new YXShop.BLL.Store.Store();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Response.CacheControl = "no-cache";
                Response.Expires = 0;
                ProList.InnerHtml = StoreList();
            }
        }

        private string StoreList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.Model.Admin.AdminInfo admin = YXShop.Common.AdministrorManager.Get();
            YXShop.BLL.Admin.Administrators adminBll = new BLL.Admin.Administrators();
            if (admin != null)
            {
                //如果当前用户是总部用户，那么能够选择所有门店。
                //如果是销售中心用户，只能选择该用户管理的销售中心下面的门店。
                //如果是门店用户，只能选择该用户管理的门店
                ChangeHope.DataBase.DataByPage dataPage;
                if (admin.AdminType == 1)
                {
                    dataPage = bll.GetList("");
                }
                else if (admin.AdminType == 2)
                {
                    List<YXShop.Model.Store.StoreCenter> storeCenters = adminBll.GetStoreCenterAdmin_StoreCenter(admin.AdminId);
                    List<int> ids = new List<int>();
                    for (int i = 0; i < storeCenters.Count; i++)
                    {
                        ids.Add(storeCenters[i].Sid.Value);
                    }
                    dataPage = bll.GetList(ChangeHope.Common.Util.GetWhereInClause(ids, "storecenterid"));
                }
                else 
                {
                    dataPage = bll.GetList(" and adminid=" + admin.AdminId.ToString());
                }
                table.AddHeadCol("", "门店ID");
                table.AddHeadCol("", "门店名称");
                table.AddRow();
                if (dataPage.DataReader != null)
                {
                    while (dataPage.DataReader.Read())
                    {
                        table.AddCol(dataPage.DataReader["sid"].ToString());
                        table.AddCol("<span id=\"" + dataPage.DataReader["sid"].ToString() + "\" class=\"LableItem\"  onClick=\"SelectLable(this);sFiles('" + dataPage.DataReader["sid"].ToString() + "','" + dataPage.DataReader["storename"] + "');\">" + dataPage.DataReader["storename"] + "</span>");
                        // table.AddCol(dataPage.DataReader["UserId"].ToString());
                        //"<span id=\"" + dataPage.DataReader["UID"].ToString() + "\" class=\"LableItem\" ondblclick=\"ReturnValue();\" onClick=\"SelectLable(this);sFiles('" + dataPage.DataReader["UID"].ToString() + "','" + dataPage.DataReader["UserId"] + "');\">" + dataPage.DataReader["UserId"] + "</span>";
                        table.AddRow();
                    }
                }
                string view = table.GetTable() + dataPage.PageToolBar;
                dataPage.Dispose();
                dataPage = null;
                return view;
            }
            else
            {
                return "";
            }
        }
    }
}
